Skip to content

Fix #1956: cap packages/codev vitest at 3 workers (singleFork was dead since Vitest 4) - #1965

Open
waleedkadous wants to merge 7 commits into
mainfrom
builder/bugfix-1956
Open

waleedkadous wants to merge 7 commits into
mainfrom
builder/bugfix-1956

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

One run of the packages/codev unit suite (porch's tests check) took an 18-core Mac from a one-minute load of about 8 to between 30 and 59. Under that load the suite's own process-spawning tests missed their 5-second timeouts. GitHub's runners passed the same code every time.

Fixes #1956

Root cause

vitest.config.ts asked for one fork with poolOptions.forks.singleFork: true. The installed vitest is 4.1.4, and Vitest 4 removed test.poolOptions. All of this was checked in the installed package, not from memory:

  • resolveConfig only prints a deprecation for poolOptions, and nothing in vitest/dist reads singleFork.
  • With no maxWorkers, resolveMaxWorkers() returns os.availableParallelism() - 1 in run mode. That is 17 files at once on the 18-core Mac and 3 on GitHub's 4-vCPU runners (ubuntu-latest and windows-latest; the repo is public). Hence the Mac-only failures.
  • The v4 migration guide ("Pool Rework") maps maxForks to maxWorkers, singleFork to maxWorkers: 1, isolate: false, and VITEST_MAX_FORKS to VITEST_MAX_WORKERS.

vitest.cli.config.ts and vitest.e2e.config.ts, both spawn-heavy (the built binary, real Tower servers), had no cap at all.

Reproduced without a full run: on the old config, 8 small test files ran in 8 forks at once, and resolveConfig gave maxWorkers: undefined for all three configs.

Fix

  • packages/codev/vitest-workers.ts: MAX_WORKERS = 3, one shared constant used as the top-level maxWorkers in all three packages/codev configs. It replaces the dead poolOptions block in vitest.config.ts.
  • Why 3: it is what vitest already uses on GitHub's runners, so CI parallelism is unchanged and a developer machine runs the suite the way CI does. The architect agreed (a cap of 4 would have raised CI and Windows from 3 to 4).
  • Override: vitest's own VITEST_MAX_WORKERS changes the count for one run. vitest reads it itself, so this PR adds no code for it.
  • Isolation is unchanged: isolate keeps its default of true, so each file still gets a fresh fork, as it has under Vitest 4.
  • Two stale comments corrected (adjacent fix):
    • vitest-setup.ts said "with singleFork all ~200 unit files share one process".
    • The e2e config said maxConcurrency: 1 // Run sequentially. maxConcurrency only limits test.concurrent tests within one file; it never stopped files running in parallel.
  • Other configs checked: apps/{streamdeck,vscode,web}, packages/{core,sdk,artifact-canvas}. None has a dead poolOptions block, and no poolOptions or singleFork remains anywhere in the repo.

Testing

  • Regression test: src/__tests__/bugfix-1956-vitest-worker-cap.test.ts resolves each of the three configs through vitest/node's public resolveConfig and asserts maxWorkers === 3. It checks the resolved config, not the file's keys: the original bug was a key that was present but ignored. It clears VITEST_MAX_WORKERS while resolving. It fails 3/3 on the old configs (expected undefined to be 3) and passes 3/3 with the fix.

  • Targeted runs: the deprecation line no longer prints. The 8-file probe peaks at 3 forks (was 8), and 1 with VITEST_MAX_WORKERS=1. The issue's 10 spawn-heavy files run together and pass: 239 tests in 36 s, peak load 4.4.

  • The one owner-approved full local run, made through porch's own checks (porch done), 18-core Mac:

    Result green: all 429 files pass, 0 failures
    Build check 18.5 s
    Tests check (wall) 137.1 s (GitHub: 2 m 13 s at 3 workers with coverage)
    One-minute load 4.55 at start, peak 8.14, 6.29 at the end (was 30 to 59 uncapped)
    Live descendants of vitest peak 14, median 7
    Other activity not a quiet machine: other builders' targeted vitest runs were alive in 107 of 118 test-phase samples, up to 2 at once

    Slowest files (vitest results cache): spec-1280-measurement-instrument 35 s, session-manager 28 s, pir-1233-session-launch-loop 22.5 s. The issue's 10 spawn-heavy files total 73 s in the full run against 89 s run alone at the cap, so their times are normal for them, not load-inflated.

For the owner: the capped local run is green with the machine at a load of about 8. The standing rulings that let GitHub's green run stand in for porch's local tests check can be retired. That is the owner's call, not this PR's.

Review notes (CMAP: codex REQUEST_CHANGES, claude APPROVE)

  • codex, commit format: it flagged 0ff39b3, ff2f0c2 and b97dc59 for starting with chore(porch):. Those are porch's own state commits, written by porch, and main carries 92 of them in its last 200 commits. Rewording them would mean rewriting pushed history. Not changed; codex found no code, test, scope or security issues.
  • claude, test timeout: no explicit timeout was added to the regression test. Its three config resolutions took 57 ms in the full run, against the 5 s default.
  • claude, e2e cap: kept at 3, deliberately, not 1. The e2e config's old "Run sequentially" comment suggested one file at a time, but it never ran that way. CI's Tower integration job has run at 3 workers since Vitest 4, so a sequential e2e run would be a new behaviour change this issue doesn't call for.
  • claude, small machines: the cap is a fixed 3, so a 2-vCPU machine gets 3 workers where vitest would pick 1. All CI runners are 4-vCPU. A formula would make the resolved value depend on the machine.

…as dead since Vitest 4

Vitest 4 removed test.poolOptions, so poolOptions.forks.singleFork was
ignored and the unit suite ran availableParallelism() - 1 files at once
(17 on an 18-core Mac). Replace it with the top-level maxWorkers option,
from one shared constant in vitest-workers.ts, in all three packages/codev
configs (unit, cli, e2e; the cli and e2e configs had no cap at all).

3 is vitest's default on GitHub's 4-vCPU runners, so CI parallelism is
unchanged. VITEST_MAX_WORKERS overrides it for one run.

Also corrects two comments that described the old behaviour:
vitest-setup.ts's 'with singleFork all files share one process' and the
e2e config's 'maxConcurrency: 1 // Run sequentially' (maxConcurrency only
limits test.concurrent tests within one file).
…3-worker cap

Resolves vitest.config.ts, vitest.cli.config.ts and vitest.e2e.config.ts
through vitest/node's public resolveConfig and asserts maxWorkers is 3, so
a future vitest that ignores or renames the option fails this test instead
of silently restoring per-core parallelism. Fails on the pre-fix configs
(maxWorkers undefined for all three).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: one run of the packages/codev unit suite takes an 18-core Mac from load 8 to 59, and its own spawn-heavy tests then time out

1 participant